<!--# include virtual="/lib/common-head.html"  wait="yes" -->
  <title> my vue </title>
  <style>
    .layui-layout-admin .layui-body>.layui-tab-content, .layui-layout-admin .layui-body>.layui-tab-content>.layui-tab-item{
      overflow: auto !important;
    }
  </style>
<!--# include virtual="/lib/common-lib.html" -->
</head>
<body id="body">
  <form class="layui-form layui-form-pane post-form" lay-filter="jsf-form">
    <div class="layui-form-item layui-input-block">
      <button target-form="post-form" class="layui-btn layui-btn-sm ajax-post fresh-parent-table layer-msg close-iframe" url="api_menu/set"><i class="layui-icon layui-icon-ok"></i>{{ d.op }}</button>
      <!-- {$html_return|raw} -->
    </div>
  </form>
<script>
;layui.use(["rb","form","laytpl","jquery"],function(rb,form,laytpl,$){
  var url = layui.cache.apiPath + "api_menu/set";
  var tpl = "";
  var id  = rb.getParam("id",0);          // id>0
  if(id){ //编辑
    // alert("编辑" + id);
    params = JSON.parse('{"id":'+id+'}');
  } else { //添加 有parent 0+
    // alert("添加下级到 " + parent);
    params = JSON.parse('{"parent":'+rb.getParam("parent",0)+'}');
  }
  //params.sid = rb.local("uinfo").sid;
  $.ajaxSetup({
    headers: {JWT : rb.local("uinfo").sid},global: false
  });
  console.log("params",params);
  $.getJSON(url, params, function(json, textStatus) {
    // console.log(url,json);
    if(textStatus == 'success'){
      if(json.data.code){
        rb.alert(json.data.msg);
      }else{
        layui.each(json.data.jsf_tpl,function(index, el) {
            tpl += el;
        });
        // laytpl 渲染
        $(".post-form").prepend(tpl);
        form.render();
      }
    }
  });
  // 保存
  $('body').on('click','.ajax-post',function() {
    rb.log("ajax-post",'');
    var that = this,$this = $(this);
    var form = rb.parseForm($this);
    console.log("form",form);
    if(!form){ return; }
    var query = form.query,target = layui.cache.apiPath + form.target +'?id=' + id + '&sid=' + rb.local("uinfo").sid;
    if ($this.hasClass('confirm')) {
      rb.confirm($this.data('content') || '',function(index) {
        layer.close(index);
        rb.post(that, target, query);
      });
    } else {
      rb.post(that, target, query);
    }
    return false;
  });
})
</script>
</body>
</html>